greedy implementation *1100

Please click on ads to support us..

Python Code:

n, k = list(map(int, input().split()))

result = [0] * n
index = 0

for v in range(k + 1, n + 1):
    result[index] = f'{v}'
    index += 1
    
for v in range(k, 0, -1):
    result[index] = f'{v}'
    index += 1

print(' '.join(result))

C++ Code:

#include<bits/stdc++.h>
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    int n, k;
    cin >> n >> k;
    for(int i=0; i<k; i++) cout << n-i << " ";
    for(int i=1; i<=n-k; i++) cout << i << " ";
    cout << '\n';
}


Comments

Submit
0 Comments
More Questions

1706C - Qpwoeirut And The City
1697A - Parkway Walk
1505B - DMCA
478B - Random Teams
1705C - Mark and His Unfinished Essay
1401C - Mere Array
1613B - Absent Remainder
1536B - Prinzessin der Verurteilung
1699B - Almost Ternary Matrix
1545A - AquaMoon and Strange Sort
538B - Quasi Binary
424A - Squats
1703A - YES or YES
494A - Treasure
48B - Land Lot
835A - Key races
1622C - Set or Decrease
1682A - Palindromic Indices
903C - Boxes Packing
887A - Div 64
755B - PolandBall and Game
808B - Average Sleep Time
1515E - Phoenix and Computers
1552B - Running for Gold
994A - Fingerprints
1221C - Perfect Team
1709C - Recover an RBS
378A - Playing with Dice
248B - Chilly Willy
1709B - Also Try Minecraft